package com.burstly.lib.component;

import com.burstly.lib.constants.UriConstants;
import com.burstly.lib.feature.FeatureFactory;
import com.burstly.lib.feature.currency.ICurrencyManager;
import com.burstly.lib.network.beans.RequestData;
import com.burstly.lib.network.beans.ResponseBean;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.network.beans.TrackClickRequest;
import com.burstly.lib.network.beans.TrackClickRequest.Request;
import com.burstly.lib.network.beans.TrackClickResult;
import com.burstly.lib.network.beans.TrackShowRequest;
import com.burstly.lib.network.beans.TrackShowRequest.Request;
import com.burstly.lib.network.beans.cookie.CookieManager;
import com.burstly.lib.network.request.AbortableAsyncTask;
import com.burstly.lib.network.request.DefaultRequestCallback;
import com.burstly.lib.network.request.RequestManager;
import com.burstly.lib.network.request.RequestManager.RequestDataObject;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

class TrackRequestSender
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private AdaptorController mController;
  private String mTag;

  public TrackRequestSender(AdaptorController paramAdaptorController)
  {
    this.mController = paramAdaptorController;
  }

  private void doClickTrack(String paramString)
  {
    ComponentState localComponentState = this.mController.getCurrentState();
    if (localComponentState != null)
    {
      ResponseBean.ResponseData localResponseData = localComponentState.getResponseData();
      ResponseBean localResponseBean = localComponentState.getFullResponse();
      if ((localResponseData != null) && (localResponseBean != null))
      {
        String str = Utils.generateUID();
        TrackClickRequest.Request localRequest = this.mController.getTrackClickRequest().getData();
        localRequest.setId(str);
        localRequest.setEncData(localResponseData.getClkData());
        localRequest.setClickDestUrl(paramString);
        localRequest.setCookie(localResponseBean.getCookie());
        localRequest.setDeviceID(Utils.getDeviceId(this.mController.getContext()));
        setAppUserId(localRequest);
        executeTrackClickRequest(this.mController.getTrackClickRequest());
        sendExternalUrlsTrack(localResponseData);
        return;
      }
      LOG.logError(this.mTag, "No current data! Can not track click request!", new Object[0]);
      return;
    }
    LOG.logWarning(this.mTag, "Can not track click. No current data.", new Object[0]);
  }

  private AbortableAsyncTask<TrackClickResult> executeTrackClickRequest(TrackClickRequest paramTrackClickRequest)
  {
    return RequestManager.makeAdRequest(new RequestManager.RequestDataObject(UriConstants.SINGLE_TRACK_CLICK_URI, paramTrackClickRequest, this.mController.getViewId(), new ClickComponentRequestCallback(this.mController, this.mTag), TrackClickResult.class), false);
  }

  private AbortableAsyncTask<String> executeTrackShowRequest(TrackShowRequest paramTrackShowRequest)
  {
    return RequestManager.makeAdRequest(new RequestManager.RequestDataObject(UriConstants.SINGLE_TRACK_URI, paramTrackShowRequest, this.mController.getViewId(), new ShowComponentRequestCallback(this.mController, this.mTag), String.class), false);
  }

  private void sendExternalUrlsTrack(ResponseBean.ResponseData paramResponseData)
  {
    String[] arrayOfString = paramResponseData.getCbca();
    if ((arrayOfString != null) && (arrayOfString.length > 0))
    {
      int i = arrayOfString.length;
      for (int j = 0; j < i; j++)
        RequestManager.makeTrackEventRequest(arrayOfString[j], this.mController.getViewId());
    }
  }

  private void sendPixelsShowRequest(String[] paramArrayOfString)
  {
    String str1 = this.mController.getViewId();
    int i = paramArrayOfString.length;
    for (int j = 0; j < i; j++)
    {
      String str2 = paramArrayOfString[j];
      if ((str2 != null) && (!"".equals(str2)))
        RequestManager.makeTrackEventRequest(str2, str1);
    }
  }

  private void setAppUserId(TrackClickRequest.Request paramRequest)
  {
    paramRequest.setAppUserId("");
    ICurrencyManager localICurrencyManager = FeatureFactory.getCurrencyFeature();
    if (localICurrencyManager != null)
    {
      String str = localICurrencyManager.getUserId();
      if (str != null)
        paramRequest.setAppUserId(str);
    }
  }

  void onClick()
  {
    doClickTrack(null);
  }

  void onClick(String paramString)
  {
    doClickTrack(paramString);
  }

  void onShow()
  {
    if (!this.mController.mIsPrefetchRequest)
    {
      ComponentState localComponentState = this.mController.getCurrentState();
      if (localComponentState != null)
      {
        ResponseBean.ResponseData localResponseData = localComponentState.getResponseData();
        ResponseBean localResponseBean = localComponentState.getFullResponse();
        RequestData localRequestData = localComponentState.getRequestData();
        TrackShowRequest.Request localRequest = this.mController.getTrackShowRequest().getData();
        localRequest.setPublisher(localRequestData.getPublisher());
        localRequest.setZone(localRequestData.getZone());
        localRequest.setFailedCR(localRequestData.getRvCR());
        if ((localResponseData == null) || (localResponseBean == null))
          break label142;
        localRequest.setEncData(localResponseData.getiTrkData());
        localRequest.setCookie(localResponseBean.getCookie());
        executeTrackShowRequest(this.mController.getTrackShowRequest());
        String[] arrayOfString = localResponseData.getValidCbiArray();
        if ((arrayOfString != null) && (arrayOfString.length > 0))
          sendPixelsShowRequest(arrayOfString);
      }
    }
    return;
    label142: LOG.logError(this.mTag, "No current data! Can not track show request!", new Object[0]);
  }

  void setBurstlyViewId()
  {
    this.mTag = (this.mController.getViewId() + " track request sender -> " + this.mController.mNetworkName);
  }

  private static class ClickComponentRequestCallback extends DefaultRequestCallback<TrackClickResult>
  {
    private final Reference<AdaptorController> mComponent;
    private final String mLogTag;

    ClickComponentRequestCallback(AdaptorController paramAdaptorController, String paramString)
    {
      this.mLogTag = paramString;
      this.mComponent = new WeakReference(paramAdaptorController);
    }

    public void onFailUi(TrackClickResult paramTrackClickResult)
    {
      TrackRequestSender.LOG.logInfo(this.mLogTag, "Click track response is not valid.", new Object[0]);
    }

    public void onSuccessUi(TrackClickResult paramTrackClickResult)
    {
      AdaptorController localAdaptorController = (AdaptorController)this.mComponent.get();
      if (localAdaptorController != null)
      {
        CookieManager.saveCookies(paramTrackClickResult.getCookie());
        localAdaptorController.defaultPostClickCallback(paramTrackClickResult);
        TrackRequestSender.LOG.logInfo(this.mLogTag, "Click tracked.", new Object[0]);
      }
    }

    public void preExecute()
    {
      TrackRequestSender.LOG.logInfo(this.mLogTag, "Tracking advertise click...", new Object[0]);
    }
  }

  private static class ShowComponentRequestCallback extends DefaultRequestCallback<String>
  {
    private final Reference<AdaptorController> mComponent;
    private final String mLogTag;

    ShowComponentRequestCallback(AdaptorController paramAdaptorController, String paramString)
    {
      this.mLogTag = paramString;
      this.mComponent = new WeakReference(paramAdaptorController);
    }

    public void onFailUi(String paramString)
    {
      TrackRequestSender.LOG.logError(this.mLogTag, "Error tracking show. Track result is null", new Object[0]);
    }

    public void onSuccessUi(String paramString)
    {
      if ((AdaptorController)this.mComponent.get() != null)
      {
        if (Boolean.parseBoolean(paramString))
          TrackRequestSender.LOG.logInfo(this.mLogTag, "Showing advertise successfully tracked on server. Track result: {0}", new Object[] { paramString });
      }
      else
        return;
      TrackRequestSender.LOG.logInfo(this.mLogTag, "Showing advertise wasn't tracked on server. Track result: {0}", new Object[] { paramString });
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.TrackRequestSender
 * JD-Core Version:    0.6.2
 */